package com.open.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.open.system.domain.LoanJuxinliTokenDO;
import com.open.system.service.LoanAdminLogService;
import com.open.system.service.LoanJuxinliTokenService;
import com.open.common.controller.BaseController;
import com.open.common.utils.PageUtils;
import com.open.common.utils.Query;
import com.open.common.utils.R;

/**
 */
 
@Controller
@RequestMapping("/system/loanJuxinliToken")
public class LoanJuxinliTokenController extends BaseController {
	@Autowired
	private LoanJuxinliTokenService loanJuxinliTokenService;
	
	@Autowired
	private LoanAdminLogService loanAdminLogService;
	
	@GetMapping()
	@RequiresPermissions("system:loanJuxinliToken:loanJuxinliToken")
	String LoanJuxinliToken(){
	    return "system/loanJuxinliToken/loanJuxinliToken";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:loanJuxinliToken:loanJuxinliToken")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<LoanJuxinliTokenDO> loanJuxinliTokenList = loanJuxinliTokenService.list(query);
		int total = loanJuxinliTokenService.count(query);
		PageUtils pageUtils = new PageUtils(loanJuxinliTokenList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:loanJuxinliToken:add")
	String add(){
	    return "system/loanJuxinliToken/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:loanJuxinliToken:edit")
	String edit(@PathVariable("id") Long id,Model model){
		LoanJuxinliTokenDO loanJuxinliToken = loanJuxinliTokenService.get(id);
		model.addAttribute("loanJuxinliToken", loanJuxinliToken);
	    return "system/loanJuxinliToken/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:loanJuxinliToken:add")
	public R save( LoanJuxinliTokenDO loanJuxinliToken){
		if(loanJuxinliTokenService.save(loanJuxinliToken)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:loanJuxinliToken:edit")
	public R update( LoanJuxinliTokenDO loanJuxinliToken){
		loanJuxinliTokenService.update(loanJuxinliToken);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:loanJuxinliToken:remove")
	public R remove( Long id){
		if(loanJuxinliTokenService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:loanJuxinliToken:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		loanJuxinliTokenService.batchRemove(ids);
		return R.ok();
	}
	
}
